/*
 * Klienckie odzwierciedlenie PlayerStats z serwera, żadna akcja nie jest w tej klasie wykonywana
 * tutaj przechowywane są tylko staty playera
 * 
 * Konstruktor - na wejście potrzebny jest string wygenerowany przez serwer
 *               tj. z metody parsePlayer z klasy Parser, wszystkie potrzebne wektory i inty zostaną zapełnione
 *               (alternatywnie na wejście można wrzucić gotowe dane, stąd 2 konstruktory)
 * 
 * metoda do wywołania:
 *          reparse - gdy chcemy uaktualnić staty playera, wystarczy wywołać tą metodę, jako wejście
 *                    podobnie jak przy konstruktorze używamy parsePlayer z klasy Parser na serwerze
 */
package wowmobileclient;

import java.util.Vector;

public class PlayerStats {

    private int level, image;
    private String nick, classname;
    private Vector handitems;
    private Vector handitemsdescription;
    /*
     * wearitems
     * 0 - broń
     * 1 - zbroja - napierśnik - szata
     * 2 - hełm -czapka
     * 3 - rękawice
     * 4 - buty
     */
    private Vector wearitems;
    private Vector wearitemsimage;
    private Vector wearitemsdescription;
    private Vector magiclist;
    private Vector magiclistdescription;
    private Vector magiclistimage;
    private int hp, mana, defence, attack, speed;

    //Player otrzymuje tylko prawdziwe staty jakie posiada, czyli po obliczeniu statystyk
    PlayerStats(String nick, int level, int hp, int mana, int defence, int attack, int speed, String classname, Vector handitems, Vector handitemsdescription, Vector wearitems, Vector wearitemsimage, Vector wearitemsdescription, Vector magiclist, Vector magiclistdescription, Vector magiclistimage, int image) {
        this.nick = nick;
        this.level = level;
        this.hp = hp;
        this.mana = mana;
        this.defence = defence;
        this.attack = attack;
        this.speed = speed;
        this.classname = classname;
        this.handitems = handitems;
        this.handitemsdescription = handitemsdescription;
        this.wearitems = wearitems;
        this.wearitemsdescription = wearitemsdescription;
        this.wearitemsimage = wearitemsimage;
        this.magiclist = magiclist;
        this.magiclistdescription = magiclistdescription;
        this.magiclistimage = magiclistimage;
        this.image = image;
    }

    PlayerStats(String info) {
        this.nick = new String("");
        this.level = 0;
        this.hp = 0;
        this.mana = 0;
        this.defence = 0;
        this.attack = 0;
        this.speed = 0;
        this.classname = new String("");
        this.handitems = new Vector();
        this.handitemsdescription = new Vector();
        this.wearitems = new Vector();
        this.wearitemsdescription = new Vector();
        this.wearitemsimage = new Vector();
        this.magiclist = new Vector();
        this.magiclistdescription = new Vector();
        this.magiclistimage = new Vector();
        this.image = 0;
        reparse(info);
    }

    public void reparse(String info) {
        if (!info.equals("")) {
            String[] parsed = SplitString.split(info, ";");
            for (int i = 0; i < parsed.length; i++) {
                parse(SplitString.split(parsed[i], ","));
            }
        }
    }

    private void parse(String[] partofparsed) {
        if (partofparsed[0].equals("PlayerName")) {
            this.nick = partofparsed[1];
        } else if (partofparsed[0].equals("PlayerClass")) {
            this.classname = partofparsed[1];
        } else if (partofparsed[0].equals("PlayerHp")) {
            this.hp = Integer.parseInt(partofparsed[1]);
        } else if (partofparsed[0].equals("PlayerMana")) {
            this.mana = Integer.parseInt(partofparsed[1]);
        } else if (partofparsed[0].equals("PlayerImage")) {
            this.image = Integer.parseInt(partofparsed[1]);
        } else if (partofparsed[0].equals("Magics")) {
            magiclist.removeAllElements();
            for (int i = 1; i < partofparsed.length; i++) {
                magiclist.addElement(partofparsed[i]);
            }
        } else if (partofparsed[0].equals("MagicsDescriptions")) {
            magiclistdescription.removeAllElements();
            for (int i = 1; i < partofparsed.length; i++) {
                magiclistdescription.addElement(partofparsed[i]);
            }
        } else if (partofparsed[0].equals("MagicsImage")) {
            magiclistimage.removeAllElements();
            for (int i = 1; i < partofparsed.length; i++) {
                magiclistimage.addElement(partofparsed[i]);
            }
        } else if (partofparsed[0].equals("HandItems")) {
            handitems.removeAllElements();
            for (int i = 1; i < partofparsed.length; i++) {
                handitems.addElement(partofparsed[i]);
            }
        } else if (partofparsed[0].equals("HandItemsDescriptions")) {
            handitemsdescription.removeAllElements();
            for (int i = 1; i < partofparsed.length; i++) {
                handitemsdescription.addElement(partofparsed[i]);
            }
        } else if (partofparsed[0].equals("WearItems")) {
            wearitems.removeAllElements();
            for (int i = 1; i < partofparsed.length; i++) {
                wearitems.addElement(partofparsed[i]);
            }
        } else if (partofparsed[0].equals("WearItemsImage")) {
            wearitemsimage.removeAllElements();
            for (int i = 1; i < partofparsed.length; i++) {
                wearitemsimage.addElement(partofparsed[i]);
            }
        } else if (partofparsed[0].equals("WearItemsDescriptions")) {
            wearitemsdescription.removeAllElements();
            for (int i = 1; i < partofparsed.length; i++) {
                wearitemsdescription.addElement(partofparsed[i]);
            }
        } else if (partofparsed[0].equals("PlayerDefence")) {
            this.defence = Integer.parseInt(partofparsed[1]);
        } else if (partofparsed[0].equals("PlayerAttack")) {
            this.attack = Integer.parseInt(partofparsed[1]);
        } else if (partofparsed[0].equals("PlayerSpeed")) {
            this.speed = Integer.parseInt(partofparsed[1]);
        } else if (partofparsed[0].equals("PlayerLevel")) {
            this.level = Integer.parseInt(partofparsed[1]);
        } else {
            //wtf?!
        }
    }

    public String getStats()
    {
        String tmp="";
        tmp+="Nick: "+nick+"\n";
        tmp+="Class: "+classname+"\n";
        tmp+="Level: "+level+"\n";
        tmp+="Health: "+hp+"\n";
        tmp+="Mana: "+mana+"\n";
        tmp+="Defence: "+defence+"\n";
        tmp+="Attack: "+attack+"\n";
        tmp+="Speed: "+speed;
        return tmp;
    }

    public void setClassname(String classname) {
        this.classname = classname;
    }

    public void setImage(int image) {
        this.image = image;
    }

    public void setMagiclistimage(Vector magiclistimage) {
        this.magiclistimage = magiclistimage;
    }

    public Vector getMagiclistimage() {
        return magiclistimage;
    }

    public void setHanditems(Vector handitems) {
        this.handitems = handitems;
    }

    public void setHanditemsdescription(Vector handitemsdescription) {
        this.handitemsdescription = handitemsdescription;
    }

    public void setLevel(int level) {
        this.level = level;
    }

    public void setMagiclist(Vector magiclist) {
        this.magiclist = magiclist;
    }

    public void setMagiclistdescription(Vector magiclistdescription) {
        this.magiclistdescription = magiclistdescription;
    }

    public void setWearitems(Vector wearitems) {
        this.wearitems = wearitems;
    }

    public void setWearitemsdescription(Vector wearitemsdescription) {
        this.wearitemsdescription = wearitemsdescription;
    }

    public void setWearitemsimage(Vector wearitemsimage) {
        this.wearitemsimage = wearitemsimage;
    }

    public String getClassname() {
        return classname;
    }

    public Vector getHanditems() {
        return handitems;
    }

    public Vector getHanditemsdescription() {
        return handitemsdescription;
    }

    public Vector getMagiclist() {
        return magiclist;
    }

    public Vector getMagiclistdescription() {
        return magiclistdescription;
    }

    public Vector getWearitems() {
        return wearitems;
    }

    public Vector getWearitemsdescription() {
        return wearitemsdescription;
    }

    public Vector getWearitemsimage() {
        return wearitemsimage;
    }

    public int getDefence() {
        return defence;
    }

    public int getMana() {
        return mana;
    }

    public int getAttack() {
        return attack;
    }

    public int getHp() {
        return hp;
    }

    public int getSpeed() {
        return speed;
    }

    public void setAttack(int attack) {
        this.attack = attack;
    }

    public void setDefence(int defence) {
        this.defence = defence;
    }

    public void setHp(int hp) {
        this.hp = hp;
    }

    public void setMana(int mana) {
        this.mana = mana;
    }

    public void setSpeed(int speed) {
        this.speed = speed;
    }

    public String getNick() {
        return nick;
    }

    public int getImage() {
        return image;
    }

    public void setNick(String nick) {
        this.nick = nick;
    }

    public int getLevel() {
        return level;
    }

    public String getPclass() {
        return classname;
    }

    public String getMagic()
    {
        String tmp="";
        for(int i=0; i<magiclist.size(); i++)
        {
            tmp+=magiclist.elementAt(i);
            tmp+=":\n";
            tmp+=magiclistdescription.elementAt(i);
            tmp+="\n";
        }
        return tmp;
    }

    /*
     * wearitems
     * 0 - broń
     * 1 - zbroja - napierśnik - szata
     * 2 - hełm -czapka
     * 3 - rękawice
     * 4 - buty
     */

    String getItems()
    {
        String tmp="Wear items:\n";
        tmp+="Weapon: "+wearitems.elementAt(0)+"\n"+wearitemsdescription.elementAt(0)+"\n";
        tmp+="Armor: "+wearitems.elementAt(1)+"\n"+wearitemsdescription.elementAt(1)+"\n";
        tmp+="Helmet: "+wearitems.elementAt(2)+"\n"+wearitemsdescription.elementAt(2)+"\n";
        tmp+="Gloves: "+wearitems.elementAt(3)+"\n"+wearitemsdescription.elementAt(3)+"\n";
        tmp+="Shoes: "+wearitems.elementAt(4)+"\n"+wearitemsdescription.elementAt(4)+"\n";

        tmp+="\nHand items:\n";
        for(int i=0; i<handitems.size(); i++)
        {
            tmp+=wearitems.elementAt(i);
            tmp+=":\n";
            tmp+=wearitemsdescription.elementAt(i);
            tmp+="\n";
        }

        return tmp;
    }
}
